import { buildArray } from './utils'

// 实现两数相加
export type Add<Number1 extends number, Number2 extends number> = [
    ...buildArray<Number1>,
    ...buildArray<Number2>,
]['length']

type BodyPartCost = {
    move: 50
    work: 100
    attack: 80
    carry: 50
    heal: 250
    ranged_attack: 150
    tough: 10
    claim: 600
}

// 计算部件孵化需要的能量
export type CalcCreepCost<BodyParts extends BodyPartConstant[], Cost extends number = 0> = BodyParts extends [
    infer First,
    ...infer Rest,
]
    ? First extends BodyPartConstant
        ? Rest extends BodyPartConstant[]
            ? CalcCreepCost<Rest, Add<Cost, BodyPartCost[First]> extends number ? Add<Cost, BodyPartCost[First]> : 0>
            : never
        : never
    : Cost
